<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>商品分类列表</title>

<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/bootstrap/css/bootstrap.min.css');?>" />
<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/bootstrap/css/bootstrap-responsive.min.css');?>" />
<script type="text/javascript" src="<?php echo asset_url('js/jquery/jquery.js');?>"></script>

<link rel="stylesheet" type="text/css" href="<?php echo theme_url('css/common.css');?>" />
<script type="text/javascript" src="<?php echo theme_url('js/common.js');?>"></script>

<script type="text/javascript">
	$(document).ready(function(){

		$('#tree tr:gt(0)').find('td i').css('cursor', 'pointer').toggle(function(){
			$(this).removeClass('icon-minus-sign').addClass('icon-plus-sign');
			var parent = $(this).parent().parent();
			parent.nextAll().each(function(){
				if ($(this).attr('data-level') <= parent.attr('data-level'))
				{
					return false;
				}
				else
				{
					$(this).hide();
				}
			});
		}, function(){
			$(this).removeClass('icon-plus-sign').addClass('icon-minus-sign');
			var parent = $(this).parent().parent();
			parent.nextAll().each(function(){
				if ($(this).attr('data-level') <= parent.attr('data-level'))
				{
					return false;
				}
				else
				{
					$(this).show();
				}
			});
		});

		$('#tree tr:gt(0)').each(function(){
			var level = $(this).attr('data-level');
			if (level > 1)
			{
				$(this).find('td:eq(1)').css('padding-left', (level - 1) * 70);
			}
		});

	});
</script>
</head>
<body>

	<?php echo widget('admin/header');?>

	<div id="wrap" class="container">

		<div class="btn-toolbar">
			<div class="btn-group">
				<a href="<?php echo admin_url('category/insert');?>" class="btn">添加商品分类</a>
			</div>
			<div class="btn-group">
				<button class="btn dropdown-toggle" data-toggle="dropdown">导出 <span class="caret"></span></button>
				<ul class="dropdown-menu">
					<li><a href="<?php echo admin_url('category/export', array('type' => 'excel'));?>">EXCEL</a></li>
					<li><a href="<?php echo admin_url('category/export', array('type' => 'txt'));?>">文本</a></li>
				</ul>
			</div>
		</div>
		
		<table class="table table-bordered" id="tree">
			<tr>
				<th width="10%">ID</th>
				<th>名称</th>
				<th width="10%">操作</th>
			</tr>

			<?php foreach ($list as $row) {?>
			<tr data-level="<?php echo $row['level'];?>">
				<td><?php echo $row['id'];?></td>
				<td>
					<i class="icon-minus-sign"></i>
					&nbsp;&nbsp;[排序：<?php echo $row['sequence'];?>]
					&nbsp;&nbsp;<a href="<?php echo admin_url('category/update', array('id'=>$row['id']));?>" title="修改"><?php echo $row['name'];?></a>
				</td>
				<td>
					<a href="<?php echo admin_url('goods/index', array('category_id'=>$row['id']));?>" class="icon-list-alt" title="商品列表"></a>
					<a href="<?php echo admin_url('category/insert', array('parent_id'=>$row['id']));?>" class="icon-plus" title="增加子类"></a>
					<a href="<?php echo admin_url('category/update', array('id'=>$row['id']));?>" class="icon-edit" title="修改"></a>
					<a href="<?php echo admin_url('category/delete', array('id'=>$row['id']));?>" onclick="return false;" class="delete icon-remove" title="删除"></a>
				</td>
			</tr>
			<?php }?>
			
		</table>
		
	</div>
	
	<?php echo widget('admin/footer');?>

</body>
</html>